//
//  RDBaseViewController.m
//  ReverseDiabetes
//
//  Created by 王佩璇 on 2024/8/17.
//

#import "RDBaseViewController.h"

@interface RDBaseViewController ()

@end

@implementation RDBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    if (self.navigationController.viewControllers.count > 1
        ) {
//        [self barButtonImageName:@"返回" targer:@"navBackClick" isRight:NO];
        [self navButtonImageName:@"系统返回" targer:@"navBackClick" isRight:NO color:UIColor.clearColor];
    }
    
}
-(void)navBackClick{
    [self.navigationController popViewControllerAnimated:YES];
}




//添加BarButtonItem
- (UIButton *)navButtonImageName:(NSString *)imageName targer:(NSString *)targerName isRight:(BOOL)right color:(UIColor *)bgColor
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 0, 35,35);
    [btn setBackgroundColor:bgColor];
    [btn setImage:[UIImage imageNamed:imageName]  forState:UIControlStateNormal];
    
//    btn.borderWidth(3).borderColor(BlackColor).conrnerRadius(10).showVisual();
    
    SEL action = NSSelectorFromString(targerName);
    [btn addTarget:self action:action forControlEvents:UIControlEventTouchUpInside];
        
    
    if (right) {
        btn.imageEdgeInsets  = UIEdgeInsetsMake(0, 0, 0, 0);
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:btn];
    }else
    {
        btn.imageEdgeInsets  =  UIEdgeInsetsMake(0, -30, 0, 0);
        self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:btn];
    }
    return btn;
}


@end
